#ifndef __JCFF_STC_TIM_H
#define __JCFF_STC_TIM_H

#ifdef __cplusplus
 extern "C" {
#endif

#include "jcff_stc_8a_config.h"

typedef enum
{
    INTERNAL_SOURCE = 0,
    EXTERNAL_SOURCE
} TIM_SourceType;
typedef enum
{
    TIM0 = 0,
    TIM1,
    TIM2,
    TIM3,
    TIM4,
} TIM_Type;

typedef enum
{
    TIMER01234_16BIT_RELOAD = 0,
    TIMER01_16BIT_ONCE,
    TIMER01_8BIT_RELOAD,
    TIMER0_16BIT_RELOAD_NMI
} TIM_ModeType;

typedef enum
{
    TIM_PRESCALER_1 = 0,            /*Config timer internal source clock not prescaler, time_clk = fclk*/
    TIM_PRESCALER_12                /*Config timer internal source clock 12 prescaler, time_clk = fclk / 12*/
} TIM_PrescalerType;

typedef union 
{
    uint8_t TIMCount_Format8b[2];
    uint16_t TIMCount_Format16b;
} TIM_PeriodType;


typedef struct 
{
    TIM_ModeType TIM_Mode;          /*Timer counter mode, 16bit reload or 8bit*/
    TIM_SourceType TIM_Source;      /*Timer counter pluse source, internal source or external source*/
    BOOL EN_CLK_OUTPUT;
    BOOL EN_GATE;
    TIM_PrescalerType Prescaler;
    TIM_PeriodType Period;
} TIM_InitTypeDef;

#define TIM_CounterRegisterType TIM_PeriodType 

RV TIM_Init(TIM_Type TIM, TIM_InitTypeDef *TIM_Init);
void TIM_CountSwitch(TIM_Type TIM, BOOL status);
void TIM_GetCurrentCount(TIM_Type TIM, TIM_CounterRegisterType *CntReg);

#ifdef __cplusplus
}
#endif

#endif